package jvmtest;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2022/02/03/17:13
 * @Description:
 */

import java.lang.reflect.Field;
import sun.misc.Unsafe;

/**
 *@ClassName DirectMemoryOOM
 *@Description
 *@Author 王琛
 *@Date 2022/2/3 17:13
 @Version 1.0
 */
public class DirectMemoryOOM {
    private static final int _1MB_ = 1024 * 1024;

    public static void main(String[] args) throws IllegalAccessException {
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];
        unsafeField.setAccessible(true);
        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        while (true){
            unsafe.allocateMemory(_1MB_);
        }
    }

}
